// 引入用户集合
const User = require("../../model/user");
module.exports = async(req, res) => {
    // 登录成功之后将用户信息返回给前端，前端再将用户信息存储在sessionStorage中,以便日后使用,注意: node中没有window对象,
    let { username, password } = req.body;
    let user = await User.findOne({ username });
    let resData = {
        data: user,
        meta: {
            code: 200,
            msg: "登录成功",
        },
    };
    if (!user) {
        resData.meta.code = 400;
        resData.meta.msg = "该用户不存在";
        resData.data = {};
        res.send(resData);
    } else if (password !== user.password) {
        resData.meta.code = 400;
        resData.meta.msg = "密码错误!";
        resData.data = {};
        res.send(resData);
    } else {
        res.send(resData);
    }
};